from flask import Blueprint, request, jsonify
from app.services import UserService

bp = Blueprint('user', __name__)

@bp.route('/profile', methods=['GET'])
def get_profile():
    """获取用户信息（需通过其他方式验证身份）"""
    user_id = request.args.get('user_id', type=int)
    result = UserService.get_user_profile(user_id)
    return jsonify(result), result['code']

@bp.route('/update', methods=['PUT'])
def update_info():
    """更新用户信息"""
    user_id = request.args.get('user_id', type=int)
    result = UserService.update_user_info(
        user_id=user_id,
        **request.get_json()
    )
    return jsonify(result), result['code']

# 查询当前登录用户的学生id
@bp.route('/getCurrentStudentId/<int:user_id>', methods=['GET'])
def get_student_id(user_id):  # 接收URL参数
    result = UserService.get_student_id(user_id)
    return jsonify(result), result['code']
